-- 下载插件 chi_sim.traineddata
-- https://helpdoc.touchsprite.com/dev_docs/21/1.html

local RxTsDownload = {}

function RxTsDownload:haveFile_chi_sim()
  local file = userPath()..'/res/tessdata/chi_sim.traineddata'
  local ctn = RxDhFile:file_exist(file)
  RxLog('chi_sim.traineddata file_exist='..tostring(ctn))
  return ctn
end

function RxTsDownload:chi_sim()
  local file = userPath()..'/res/tessdata/chi_sim.traineddata'
  local ctn = RxDhFile:file_exist(file)
  RxLog('chi_sim.traineddata file_exist='..tostring(ctn))
  if not ctn then
    local url = 'https://video.touchsprite.com/%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3/%E4%B8%AD%E8%8B%B1%E6%96%87%E5%AD%97%E5%BA%93/chi_sim.traineddata'
    ctn = RxTsDownload:down(file, url)
  end
  return ctn
end

function RxTsDownload:down(filePath, url)
  local ctn = 0
  if not filePath then return 0 end
  if not url then return 0 end
  local ts = require("ts")
  local code,msg = ts.tsDownload(filePath,url)
  local res = '失败'
  if code == 200 then
    ctn = 1
    res = '成功'
  end
  RxLog('RxTsDownload:down ctn='..res..' -code='..tostring(code)..' msg='..tostring(msg))
  return ctn
end

return RxTsDownload